'''
Created on Jan 8, 2015

'''
                           
def file_analysis(file_dir):
    '''
    open a txt file
    analysis the file
    output the data
    '''
    data_list = []
    dict = {}
    id = 0
    
    fp = open(file_dir,'r',-1)
    
    for eachLine in fp:
        
        if eachLine[0].isdigit():
            data_list.append(dict)
            type = ""
            base_line = ""
            change_line = ""
            base_code = []
            change_cdoe = []
            id += 1
            for i,ch in enumerate(eachLine):
                if ch.isalpha():
                    base_line = eachLine[0:i]
                    change_line = eachLine[i+1:-1]
                    type = ch
        else:
            if eachLine[0] == "<":
                base_code.append(eachLine[1:-1].strip())
            if eachLine[0] == ">":
                change_cdoe.append(eachLine[1:-1].strip())
            dict={id:[base_line,change_line,base_code,change_cdoe,type]}
    data_list.append(dict)

    fp.close()
    
file_analysis("testfile.txt")